/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:assign-tracer
 * Create Time: 2016年2月15日 上午10:32:49
 */
package com.lenovo.lmrp.server.assigntracer.repository;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Scopes;
import com.lenovo.lmrp.server.assigntracer.domain.engineer.IEngineerRepository;
import com.lenovo.lmrp.server.assigntracer.domain.ticket.ITicketRepository;
import com.lenovo.lmrp.server.assigntracer.domain.workflow.IProcessService;

/**
 * @author songyz
 *
 */
public abstract class ARepositoryFactory {
	private static ARepositoryFactory factory;

	public static ARepositoryFactory getFactory() {
		return factory;
	}

	@Inject
	public static void setFactory(ARepositoryFactory factory) {
		ARepositoryFactory.factory = factory;
	}

	public abstract IEngineerRepository getEngineerRepository();

	public abstract ITicketRepository getTicketRepository();

	public abstract BaseInfoRepository getBaseInfoRepository();

	public abstract WorkflowRepository getWorkflowRepository();

	public abstract IProcessService getIProcessService();

	@Named("default")
	public static class RepositoryFactoryImpl extends ARepositoryFactory {

		@Inject
		private IEngineerRepository engineerRepository;

		@Inject
		private ITicketRepository ticketRepository;

		@Inject
		private BaseInfoRepository baseInfoRepository;

		@Inject
		private WorkflowRepository workflowRepository;
		@Inject
		private IProcessService processService;

		public IEngineerRepository getEngineerRepository() {
			return engineerRepository;
		}

		public ITicketRepository getTicketRepository() {
			return ticketRepository;
		}

		@Override
		public BaseInfoRepository getBaseInfoRepository() {
			return baseInfoRepository;
		}

		@Override
		public WorkflowRepository getWorkflowRepository() {
			return workflowRepository;
		}

		@Override
		public IProcessService getIProcessService() {
			return processService;
		}
	}

	public static class RepositoryModule implements Module {

		@Override
		public void configure(Binder binder) {
			binder.bind(IEngineerRepository.class).to(EngineerRepository.class).in(Scopes.SINGLETON);
			binder.bind(ITicketRepository.class).to(TicketRepository.class).in(Scopes.SINGLETON);
			binder.bind(BaseInfoRepository.class).in(Scopes.SINGLETON);
			binder.bind(WorkflowRepository.class).in(Scopes.SINGLETON);

			binder.bind(ARepositoryFactory.class).to(RepositoryFactoryImpl.class).in(Scopes.SINGLETON);

			binder.requestStaticInjection(ARepositoryFactory.class);
		}

	}
}
